import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

ApplicationWindow {
    id: window
    flags: Qt.FramelessWindowHint | Qt.WA_TranslucentBackground
    default property alias content: windowContent.data
    property color primaryColor: "green"
    property Item bottomContent
    property int titlebarHeight: 35
    property int statusbarHeight: 35

    ColumnLayout {
        spacing: 0
        anchors.fill: parent
        Rectangle {
            Layout.fillWidth: true
            height: window.titlebarHeight
            color: window.primaryColor
            WindowHandle {
                anchors.fill: parent
                window: window
            }
            Row {
                anchors.fill: parent
                anchors.leftMargin: 5
                anchors.rightMargin: 5
                spacing: 5
                Rectangle {
                    width: 20
                    height: 20
                    color: "red"
                    radius: 10
                    anchors.verticalCenter: parent.verticalCenter
                    border.color: Qt.lighter("red", 0.9)
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            window.close()
                        }
                    }
                }
                Rectangle {
                    width: 20
                    height: 20
                    color: "yellow"
                    radius: 10
                    anchors.verticalCenter: parent.verticalCenter
                    border.color: Qt.lighter("yellow", 0.9)
                    MouseArea {
                        hoverEnabled: true
                        anchors.fill: parent
                        onClicked: {
                            if (window.visibility == 4) window.showNormal(); else window.showMaximized()
                        }
                    }
                }
                Rectangle {
                    width: 20
                    height: 20
                    color: "green"
                    radius: 10
                    anchors.verticalCenter: parent.verticalCenter
                    border.color: Qt.lighter("green", 0.9)
                    MouseArea {
                        anchors.fill: parent
                        onClicked: {
                            window.showMinimized();
                        }
                    }
                }
            }
            Text {
                anchors.centerIn: parent
                text: window.title
                color: "white"
            }
        }
        Rectangle {
            id: windowContent
            Layout.fillWidth: true
            Layout.fillHeight: true
        }
        Rectangle {
            Layout.fillWidth: true
            height: window.statusbarHeight
            color: window.primaryColor
            data: window.bottomContent
        }
    }
}
